import request from "@/utils/request.js";

const Api = {
    create: "/v1/data/dictType",
    export: "/v1/data/dictType/export",
    delete: "/v1/data/dictType/",
    batchDelete: "/v1/data/dictType/batch/del",
    update: "/v1/data/dictType/",
    getList: "/v1/data/dictType",
    getDictIdList: "/v1/data/dictType/dict/",
    getDictNameList: "/v1/data/dictType/dict/name?dict_name=",
    getTree: "/v1/data/dict/tree/list",
    getObj: "/v1/data/dictType/",
}

/**
 * 创建字典类型
 */
export const create_dictType = (data) => {
    return request({
        url: Api.create,
        method: "POST",
        data,
    });
};

/**
 * 导入字典类型
 */
export const export_dictType = (data) => {
    return request({
        url: Api.export,
        method: "POST",
        headers: {
            "Content-Type": "multipart/form-data",
        },
        data,
    });
};

/**
 * 删除字典
 */
export const delete_dictType = (id) => {
    return request({
        url: Api.delete + id,
        method: "DELETE",
    });
};

/**
 * 批量删除字典
 */
export const batch_delete_dictType = (ids) => {
    return request({
        url: Api.batchDelete,
        method: "DELETE",
        data: ids,
    });
};

/**
 * 更新字典
 */
export const update_dictType = (id, data) => {
    return request({
        url: Api.update + id,
        method: "PUT",
        data,
    });
};

/**
 * 获取分页字典id字段类型列表
 */
export const get_dictIdType_list = (id) => {
    return request({
        url: Api.getDictIdList + id,
        method: "GET",
    });
};

/**
 * 根据字典名称获取字典类型列表
 */
export const get_dictType_name = (name) => {
    return request({
        url: Api.getDictNameList + name,
        method: "GET",
    });
};

/**
 * 获取分页字典类型列表
 */
export const get_dictType_list = (params) => {
    return request({
        url: Api.getList,
        method: "GET",
        params,
    });
};

/**
 * 获取字典类型
 */
export const get_dictType_obj = (id) => {
    return request({
        url: Api.getObj + id,
        method: "GET",
    });
};